<script setup lang="ts">
import { ref } from 'vue';
import { MenuItem } from '../enum/menuEnum';

const props = defineProps<{
  projectName: string
  menu: MenuItem
}>()

const emit = defineEmits<{
  (e: 'menu-click', selectedMenu: MenuItem): void
}>()

const currentMenu = ref<MenuItem>(props.menu || MenuItem.AggregateRoot);

// 定义菜单项点击事件
function handleMenuClick(menu: MenuItem) {
  currentMenu.value = menu;
  emit('menu-click', currentMenu.value);
}

function menuClass(menu: MenuItem) {
  if (menu === '关闭项目') {
    return 'close-item'
  }
  if (menu === currentMenu.value) {
    return 'selected'
  }
}

</script>

<template>

  <nav class="vertical-menu">
    <header class="detail-header">
      <h1 class="project-title">{{ projectName }}</h1>
    </header>
    <ul>
      <li v-for="menu in MenuItem" @click="handleMenuClick(menu)" :class="menuClass(menu)">{{ menu }}</li>
    </ul>
  </nav>
</template>

<style scoped>
.detail-header {
  align-items: center;
  gap: 12px;
  padding: 30px;
  background-color: #40a9ff;
  border-bottom: 1px solid #dee2e6;
  width: 200px;
  box-sizing: border-box;
}

.project-title {
  color: white;
  margin: 0;
  font-size: 18px;
  text-align: center;
  width: 100%;
}

.vertical-menu {
  width: 200px;
  position: fixed;
  left: 0;
  top: 0;
  background-color: #ffffff;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
  z-index: 100;
  height: 100%;
  border-radius: 0 10px 10px 0;
}

.vertical-menu header {
  border-radius: 0 10px 0 0;
}

.vertical-menu ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

.vertical-menu li {
  padding: 10px 15px;
  margin: 5px 5px;
  cursor: pointer;
  border: none;
  transition: all 0.3s ease;
  border-radius: 10px;
}

.vertical-menu li:hover {
  background-color: #a4d5ec;
}

.vertical-menu .close-item {
  color: #dc3545;
  font-weight: bold;
}

.vertical-menu .close-item:hover {
  background-color: #f8d7da;
}

.vertical-menu .selected {
  background-color: #a4d5ec;
}
</style>